package com.zhouyu.service;

import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;

import javax.annotation.PostConstruct;
import java.util.Date;

@Component
public class UserService implements InitializingBean, ApplicationContextAware,BeanNameAware, SmartInitializingSingleton {

	private FavoriteService favoriteService;
	@Autowired
	private OrderService orderService;

	public UserService() {
		/**
		 * order0 instantiateBean 实例化
		 * @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBean(String, RootBeanDefinition, Object[])
		 */
		System.out.println("constructor");
	}


	@PostConstruct
	public void postConstruct() {
		System.out.println("@PostConstruct"); //order3
	}



	public void test(){
		System.out.println(orderService);
	}

	public void a(){
		System.out.println("a");
	}


	@Override
	public void afterPropertiesSet() throws Exception {
		/**
		 * order4
		 * @see AbstractAutowireCapableBeanFactory#invokeInitMethods
		 */
		System.out.println("afterPropertiesSet:invokeInitMethods中调用");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

		/** order2
		 * @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#initializeBean(Object, String)
		 * @see org.springframework.context.support.ApplicationContextAwareProcessor#postProcessBeforeInitialization(Object, String)
		 *
		 */

		System.out.println("setApplicationContext:在beanPostProcessorBefore调用");
	}

	@Override
	public void setBeanName(String name) {
		/**
		 * order1
		 * @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#invokeAwareMethods(String, Object) 
		 */
		System.out.println("BeanName is "+name+",在beanPostProcessorBefore之前的invokeAware调用");  //invokeAwareMethods
	}

	@Override
	public void afterSingletonsInstantiated() {
		System.out.println("afterSingletonsInstantiated:所有非懒加载bean加载之后,调用");
	}


	public FavoriteService getFavoriteService() {
		return favoriteService;
	}

	public void setFavoriteService(FavoriteService favoriteService) {
		this.favoriteService = favoriteService;
	}
}
